<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, student-scalable=no" />
    <title>${siteName!""}|学生管理-编辑学生</title>
    <#include "../common/header.ftl"/>

    <!--时间选择插件-->
    <link rel="stylesheet" href="/admin/js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css">
    <!--日期选择插件-->
    <link rel="stylesheet" href="/admin/js/bootstrap-datepicker/bootstrap-datepicker3.min.css">
    <link href="/admin/css/style.min.css" rel="stylesheet">

</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar">
            <div class="lyear-layout-sidebar-scroll">
        <#include "../common/left-menu.ftl"/>
      </div>
        </aside>
        <!--End 左侧导航-->
        <#include "../common/header-menu.ftl"/>
        <!--页面主要内容-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header"><h4>编辑学生</h4></div>
                            <div class="card-body">
                                <form action="add" id="student-add-form" method="post" class="row">
                                    <input type="hidden" name="id" value="${student.id}">
                                    <input type="hidden" name="studentId" value="${student.studentId}">

                                    <div class="input-group m-b-10">
                                        <span class="input-group-addon">学生姓名</span>
                                        <input type="text" class="form-control required" id="studentName" name="studentName" value="${student.studentName}" placeholder="请输入学生名" tips="请填写学生名" />
                                    </div>
                                    <div class="input-group m-b-10">
                                        <span class="input-group-addon">登录密码</span>
                                        <input type="password" class="form-control required" id="password" name="password" value="${student.password}" placeholder="请输入登录密码" tips="请填写登录密码" />
                                    </div>
                                    <div class="input-group m-b-10">
                                        <span class="input-group-addon">所属学院</span>
                                        <select name="faculties" class="form-control" id="faculties" onchange="changeCatee()">
                                            <option value="0">---请选择---</option>
                                            <#list facultiess as faculties>
                                                <option value="${faculties.id}" <#if student.faculties.id == faculties.id>selected</#if> >${faculties.name}</option>
                                            </#list>
                                        </select>
                                    </div>
                                    <div class="input-group m-b-10">
                                        <span class="input-group-addon">所属班级</span>
                                        <select  name="clazz" class="form-control" id="clazz">
                                            <option value="${student.clazz.id}">${student.clazz.name}</option>
                                        </select>
                                    </div>
                                    <div class="input-group m-b-10">
                                        <span class="input-group-addon">手机号码</span>
                                        <input type="tel" class="form-control" id="mobile" name="mobile" value="${student.mobile}" />
                                    </div>
                                    <input type="hidden" name="role" value="${student.role.id}">
                                    <div class="input-group" style="margin-top:15px;margin-bottom:15px;padding-left:25px;">
                                        性别：
                                        <label class="lyear-radio radio-inline radio-primary" style="margin-left:30px;">
                                            <input type="radio" name="sex" value="1" <#if student.sex == 1> checked </#if> >
                                            <span>男</span>
                                            <label class="lyear-radio radio-inline radio-primary">
                                                <input type="radio" name="sex" value="2" <#if student.sex == 2> checked </#if>>
                                                <span>女</span>
                                    </div>
                                    <div class="form-group col-md-12">
                                        <button type="button" class="btn btn-primary ajax-post" id="add-form-submit-btn">确 定</button>
                                        <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);return false;">返 回</button>
                                    </div>
                                </form>

                            </div>
                        </div>
                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>
<#include "../common/footer.ftl"/>
<script type="text/javascript" src="/admin/js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="/admin/js/main.min.js"></script>

<script type="text/javascript" src="/admin/js/perfect-scrollbar.min.js"></script>
<!--时间选择插件-->
<script src="/admin/js/bootstrap-datetimepicker/moment.min.js"></script>
<script src="/admin/js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script src="/admin/js/bootstrap-datetimepicker/locale/zh-cn.js"></script>
<!--日期选择插件-->
<script src="/admin/js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script src="/admin/js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<script type="text/javascript" src="/admin/js/main.min.js"></script>

<script type="text/javascript">

    var facultiesId1 = ${facultiesId};
    var clazzId = ${clazzId};

    function changeCatee(){
        var  facultiesId = $("#faculties").find("option:selected").val();
        $.ajax({
            url:"edit/faculties",
            type:"post",
            dataType:"json",
            data: {
                id:facultiesId,
            },
            success: function (data) {
                console.log(data);
                var html='<option value=\'\'>---请选择---</option>';
                $("#clazz").empty();
                for(var i = 0, len = data.length; i < len; i++)
                {
                    html+="<option value='" + data[i].id + "'>" + data[i].name + "</option>";
                }
                $("#clazz").append(html);

                if(clazzId != 0)
                {
                    $("#clazz").val(clazzId);
                }
            },
            error:function(data){
                alert('网络错误!');
            }
        });
    }
    $(document).ready(function(){
        //提交按钮监听事件
        $("#add-form-submit-btn").click(function(){
            if(!checkForm("student-add-form")){
                return;
            }
            var data = $("#student-add-form").serialize();
            $.ajax({
                url:'edit',
                type:'POST',
                data:data,
                dataType:'json',
                success:function(data){
                    if(data.code == 0){
                        showSuccessMsg('学生编辑成功!',function(){
                            window.location.href = 'list';
                        })
                    }else{
                        showErrorMsg(data.msg);
                    }
                },
                error:function(data){
                    alert('网络错误!');
                }
            });
        });
        //监听上传图片按钮
        $("#add-pic-btn").click(function(){
            $("#select-file").click();
        });

        if(facultiesId1 != 0 ){
            $("#faculties").val(facultiesId1);
            changeCatee();
        }

    });
</script>
</body>
</html>
